package com.slfx.idgen.demo.idgen.config;

import com.slfx.idgen.demo.idgen.properties.IdgenProperties;
import com.slfx.idgen.demo.idgen.snowflake.IdWorker;
import com.slfx.idgen.demo.idgen.snowflake.SnowflakeIdWorkerClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@AutoConfigureBefore(SnowflakeAutoConfiguration.class)
@EnableConfigurationProperties(IdgenProperties.class)
public class IdWorkerConfiguration {

    @Value("${server.port}")
    private int port;

    private final IdgenProperties idgenProperties;

    public IdWorkerConfiguration(IdgenProperties idgenProperties) {
        this.idgenProperties = idgenProperties;
    }

    @Bean
    public IdWorker idWorker() {
        return new SnowflakeIdWorkerClient(idgenProperties.getAppName(),port);
    }
}
